﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace SqlMonitoring.Core.Logging
{
    public class TextWriterTraceListenerWithTimeCsv : TextWriterTraceListener
    {
        public TextWriterTraceListenerWithTimeCsv()
            : base()
        {
        }

        public TextWriterTraceListenerWithTimeCsv(Stream stream)
            : base(stream)
        {
        }

        public TextWriterTraceListenerWithTimeCsv(string path)
            : base(path)
        {
        }

        public TextWriterTraceListenerWithTimeCsv(TextWriter writer)
            : base(writer)
        {
        }

        public TextWriterTraceListenerWithTimeCsv(Stream stream, string name)
            : base(stream, name)
        {
        }

        public TextWriterTraceListenerWithTimeCsv(string path, string name)
            : base(path, name)
        {
        }

        public TextWriterTraceListenerWithTimeCsv(TextWriter writer, string name)
            : base(writer, name)
        {
        }

        public override void WriteLine(string message)
        {
            WriteLine(message, string.Empty);
        }

        public override void WriteLine(string message, string category)
        {
            TraceEventCache e = new TraceEventCache();
            base.Write("\"");
            base.Write(e.DateTime.ToString());
            base.Write("\";\"");

            if (category != string.Empty)
            {
                base.Write(category);
                base.Write("\";\"");
            }
            //base.WriteLine(message+" call:"+e.Callstack+" LOS:"+e.LogicalOperationStack);
            base.WriteLine(message + "\"");
        }

        public void WriteLineIf(bool condition, string message, string category)
        {
            if (condition)
            {
                WriteLine(message, category);
            }
        }
    }   
}
